<?php
class DanhSachThamSoModel extends AppModel{

    public $name = 'DanhSachThamSoModel';
    public $useTable = 'danh_sach_tham_so';
    public $primaryKey = 'id_dsts';
	
	public function layDanhSachTheoLoai($loai='',$itemCheck = '',$typeCheck = '')
	{
		$result = $this->find('list', array(
			'conditions'=> array(
				'loai' 		=> $loai,
				'trang_thai_xoa' 	=> CHUA_XOA 
			),
			'fields'	=> array(
				'DanhSachThamSoModel.id_loai',
				'DanhSachThamSoModel.ten_loai'
			),
			'order'		=> array('DanhSachThamSoModel.id_dsts')
		));
        $return = array();
		$typeCheck = ( $typeCheck != '') ? $typeCheck : 'checked' ;
        foreach ($result as $key => $value) {
            $return[$key]['value'] = $value;
            if (is_array($itemCheck) && in_array($key, $itemCheck)) {
                $return[$key]['checked'] = $typeCheck . ' = "' . $typeCheck . '"';
            } else if (!is_array($itemCheck) && $itemCheck !== '' && $key == $itemCheck) { 
                $return[$key]['checked'] = $typeCheck . ' = "' . $typeCheck . '"';
            } else {
                $return[$key]['checked'] = '';
            }
        }
        return $return;
	}	
} 